//
//  BLImage.swift
//  BLLiveTelecast
//
//  Created by BigL055 on 16/5/27.
//  Copyright © 2016年 bigL.liveTelecast.com. All rights reserved.
//

import UIKit

extension UIImage{
    
    /// 生成圆形图片
    class func bl_imageWithRoundIcon(iconImage : UIImage) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(iconImage.size, false, 0)
        let ctx : CGContextRef = UIGraphicsGetCurrentContext()!
        CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, iconImage.size.width, iconImage.size.height))
        CGContextClip(ctx)
        iconImage .drawInRect(CGRectMake(0, 0, iconImage.size.width, iconImage.size.height))
        
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        return newImage
    }
    
    /// 生成圆形图片
    class  func bl_imageWithRoundIconName(iconName : String) -> UIImage? {
        guard let image = UIImage(named: iconName) else{
            return nil
        }
        
        return   UIImage.bl_imageWithRoundIcon(image)
    }
    
    
    
    /// 返回一张没有被渲染的图片
    class  func bl_imageWithOriginalImageName(imageName : String) -> UIImage? {
        //图片nil值校验
        guard  let image = UIImage(named: imageName) else{
            return nil
        }
        // 返回一张原始图片给你
        
        return image.imageWithRenderingMode(.AlwaysOriginal)
    }
    
}
